﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using eschoolBO;

namespace ESCHOOL.admin
{
    public partial class WebForm22 : System.Web.UI.Page
    {
        admins ad = new admins();
        protected void Page_Load(object sender, EventArgs e)
        {
            btnupdate.Visible = false;
            if (!IsPostBack)
            {
                DataTable dt = ad.GetRecords(-99, "principal", "", "",false, " and");
                GridView2.DataSource = dt;
                GridView2.DataBind();
            }
        }

        protected void btnedit_Command(object sender, CommandEventArgs e)
        {
            if (e.CommandName == "Edit")
            {
                btninsert.Visible = false;
                btnupdate.Visible = true;
                DataTable dt = ad.GetRecords(Convert.ToInt64(e.CommandArgument), "principal", "", "", false, " and ");
                tbuid.Text = Convert.ToString(dt.Rows[0]["userid"].ToString());
                TextBox1.Text = dt.Rows[0]["staff_name"].ToString();
                tbuname.Text = dt.Rows[0]["username"].ToString();
                tbpass.Text = dt.Rows[0]["password"].ToString();
            }
        }

        protected void btndelete_Command(object sender, CommandEventArgs e)
        {
            if (e.CommandName == "Delete")
            {
                DataTable dt = ad.GetRecords(Convert.ToInt64(e.CommandArgument), "", "", "", false, " and ");
                ad.userid = Convert.ToInt64(dt.Rows[0]["userid"].ToString());
                ad.staff_name = "principal";
                ad.username = dt.Rows[0]["username"].ToString();
                ad.password = dt.Rows[0]["password"].ToString();
                ad.isdeleted = true;
                ad.SaveRecords();
                Response.Redirect("~/admin/Admin.aspx");
            }
        }

        protected void btninsert_Click(object sender, EventArgs e)
        {
            ad.userid = -99;
            ad.staff_name = "principal";
            ad.username = tbuname.Text;
            ad.password = tbpass.Text;
            ad.isdeleted = false;
            ad.SaveRecords();
            Response.Redirect("~/admin/Admin.aspx");
        }

        protected void btnupdate_Click(object sender, EventArgs e)
        {
            ad.userid = Convert.ToInt64(tbuid.Text);
            ad.staff_name=TextBox1.Text;
            ad.username = tbuname.Text;
            ad.password = tbpass.Text;
            ad.isdeleted = false;
            ad.SaveRecords();
            Response.Redirect("~/admin/Admin.aspx");

        }

        protected void GridView2_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {

        }

        protected void GridView2_RowEditing(object sender, GridViewEditEventArgs e)
        {

        }
    }
}
